//
//  LTContactManager.h
//  LTIM
//
//  Created by 俊松何 on 2017/4/14.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "LTContactManagerDelegate.h"
#import "LTFriendRecmondModel.h"
@class LTUser;
@class LTError,LTMessageApplyBody,LTUserConfig;

@interface LTContactManager : NSObject



@property (nonatomic,strong) NSMutableArray<id<LTContactManagerDelegate> >* contactMangerdelegateArray;



/**
 添加回调代理
 
 @param deleagte 要添加的代理
 */
-(void)addDelegate:(id<LTContactManagerDelegate>)deleagte;

/**
 移除代理

 @param delegate 要移除的代理
 */
-(void)removeDelegate:(id<LTContactManagerDelegate>)delegate;

/**
 获取所有的申请消息
 
 @return 申请消息列表<MessageAppplyBody>
 */
-(NSArray *)getAllApplyMessage;


/**
 标记所有申请消息为已读

 @return 操作是否操作成功
 */
-(BOOL)markAllApplyMessagesAsRead;

/**
 获取申请消息未读数量
 
 @return 未读消息的数量
 */
-(NSInteger)getApplyMessageWithUnRead;


/**
 更新联系人到数据库

 @param contacts ltuser数组
 */
-(void)updateContacts:(NSArray *)contacts;

-(void)updateContact:(LTUser  *)user;

/**
 获取好友列表

 @return 好友列表<LTUser>
 */
-(NSArray *)getContactsFromDB;



-(NSArray *)getSystemContactsFromDB;


-(LTUser *)getUserWithUserId:(NSString *)userId;


/**
 通过userId判断与该用户是否是好友

 @param userId 用户userId
 @return  是否是好友
 */
-(BOOL)isFriendWithUserId:(NSString *)userId;


/**
 判断是否是自己

 @param userId userId
 @return bool
 */
-(BOOL)isMyselfWithUserId:(NSString *)userId;

/**
 从本地数据库删除好友

 @return 删除成功没
 */
-(BOOL)DeleteFriendWithUserId:(NSString *)userId;

/**
 添加一个user到本地数据库

 @param user  user
 @return 添加成功没有
 */
-(BOOL)AddFriendWithUserToDB:(LTUser *)user;

/**
 从服务器得到好友列表

 @param CompletionBlock 获取的结果回调block
 */
-(void)getContactsFromServer:(void(^)(NSArray<LTUser *> *userlist,LTError *lterror))CompletionBlock;


/**
 删除好友
 
 @param user                 好友userid
 @param IsDeleteConversation   是否删除会话
 @param CompletionBlock        回调block
 */
- (void)deleteContact:(LTUser  *)user
 isDeleteConversation:(BOOL)IsDeleteConversation
           completion:(void(^)(LTUser *user, LTError *lterror))CompletionBlock;



/**
 添加好友

 @param ltuer           好友对象user
 @param message         添加的消息
 @param CompletionBlock 添加完成的block
 */
- (void)addContact:(LTUser *)ltuer
            message:(NSString *)message
         completion:(void(^)(LTUser *ltuser, LTError *ltrror))CompletionBlock;

/**
 同意加好友的申请

 @param ltuser           申请者
 @param CompletionBlock  完成的回调
 */
- (void)approveFriendRequestFromUser:(LTUser *)ltuser
                           applyBody:(LTMessageApplyBody *)body
                          completion:(void(^)(LTUser *ltuser,LTError *ltrror))CompletionBlock;

/**
 拒绝加好友的申请

 @param ltuser           申请者
 @param CompletionBlock  完成的回调
 */
- (void)declineFriendRequestFromUser:(LTUser *)ltuser
                           applyBody:(LTMessageApplyBody *)body
                          completion:(void(^)(LTUser *ltuser,LTError *ltrror))CompletionBlock;


//删除申请消息
-(BOOL)deleteAppleMessage:(NSString *)applyMessageId;



/**
 更新用户信息

 @param name 更新用户信息
 @param CompletionBlock 更新用户信息完成的block
 */
-(void)updateCurrentUserInfoName:(NSString  *)name
                      completion:(void(^)(LTError *ltrror))CompletionBlock;

-(void)updateCurrentUserInfoAvatar:(NSString  *)avatar
                        completion:(void(^)(LTError *ltrror))CompletionBlock;

-(void)updateCurrentUserInfoCover:(NSString  *)cover
                       completion:(void(^)(LTError *ltrror))CompletionBlock;

-(void)updateCurrentUserInfoSignature:(NSString  *)signature
                           completion:(void(^)(LTError *ltrror))CompletionBlock;

-(void)updateCurrentUserInfoGender:(int)gender
                        completion:(void(^)(LTError *ltrror))CompletionBlock;





/**
 获取好友配置信息(先从本地数据去去查找，没找到在去服务器去取)

 @param friendId    好友的userId
 @param CompletionBlock 获取完成的blcok
 */
-(void)getUserConfigWithFriendId:(NSString *)friendId
                                completion:(void(^)(LTUserConfig *userConfig,LTError *ltrror))CompletionBlock;



/**
 更新好友配置信息

 @param userconfig     配置model
 @param CompletionBlock  更改完成的回调
 */
-(void)updateUserConfigWithConfig:(LTUserConfig *)userconfig
                       completion:(void(^)(LTError *ltrror))CompletionBlock;




/**
 更新推荐消息

 @param recomend 推荐消息
 */
-(void)updateRecomendMessage:(NSString *)recomend;


-(LTFriendRecmondModel *)getRecomendMessage;


-(void)clearRecomendMessage;



@end
